package com.jing.weibo.service.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.jing.weibo.mapper.user.SynchrologMapper;
import com.jing.weibo.pojo.user.Synchrolog;

/**
 * 用户同步记录的Service
 * @author jing.yue
 * @version 2012/08/31 1.0.0
 */
@Component
public class SynchrologService {

	@Autowired
	private SynchrologMapper synchrologMapper;

	/**
	 * 根据用户名和用户同步的表名[或和时间]查询用户对象
	 * @param synchrolog
	 * @return
	 * @throws Exception
	 */
	public Synchrolog findByUserNameSynchrotable(Synchrolog synchrolog) throws Exception {
		// TODO Auto-generated method stub
		List<Synchrolog> list = synchrologMapper.findByUserNameSynchrotable(synchrolog);
		if(list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	/**
	 * 添加用户同步记录
	 * @param synchrolog
	 * @throws Exception
	 */
	@Transactional
	public void saveSynchrolog(Synchrolog synchrolog) throws Exception {
		// TODO Auto-generated method stub
		if(synchrolog.getNextcursor() == null || "".equals(synchrolog.getNextcursor().trim())) {
			synchrolog.setNextcursor("0");
		}
		synchrologMapper.saveSynchrolog(synchrolog);
	}

	/**
	 * 根据用户名和同步的表名修改用户同步记录信息
	 * @param synchrolog
	 * @throws Exception
	 */
	@Transactional
	public void updateSynchrolog(Synchrolog synchrolog) throws Exception {
		// TODO Auto-generated method stub
		synchrologMapper.updateSynchrolog(synchrolog);
	}

	/**
	 * 根据用户名和类型删除记录
	 * @param sl
	 * @throws Exception
	 */
	public void deleteSynchrolog(Synchrolog sl) throws Exception {
		// TODO Auto-generated method stub
		synchrologMapper.deleteSynchrolog(sl);
	}

}
